<?php
include_once($site_path."/includes/general.php");

function getAllSubject()
{
	$query="SELECT * FROM subject";
	return getData($query);
}

function getSubjectLimit($start, $n)
{
	$query="SELECT * FROM subject ORDER BY id ASC LIMIT $start,$n";
	return getData($query);
}

function getRandomSubjectLimit($start, $n)
{
	$query="SELECT * FROM subject ORDER BY RAND() LIMIT $start,$n";
	return getData($query);
}

function getSubjectById($id)
{
	$query="SELECT * FROM subject WHERE id='$id'";
	return getData($query);
}

function insertSubject($title, $category, $author, $content, $image)
{
	$query="INSERT INTO subject(title,id_category,author,content,image) VALUES('$title','$category','$author','$content','$image')";
	if (!mysql_query($query)) return false;
	return true;
}

function updateSubject($id, $title, $category, $author, $content, $image)
{
	$query="UPDATE subject SET title='$title',id_category='$category',author='$author',content='$content',image='$image' WHERE id=$id";
	if (!mysql_query($query)) return false;
	return true;
}

function deleteSubject($id)
{
	$query="DELETE FROM subject WHERE id='$id'";
	if (!mysql_query($query)) return false;
	return true;
}

?>